<template>
  <el-drawer
    size="800px"
    :append-to-body="true"
    :wrapperClosable="openType==3"
    :title="title"
    :visible="show"
    @close="handleClose"
  >
    <div class="editor_container">
      <template v-if="!topicItem">
        <div class="editor_content">
          <div v-if="openType==3" class="" v-html="$renderedDescription(propEditorValue)"></div>
          <wangEditor :isgetIndex="2" @turnWord="uploadWordToNode" v-else :editorValue.sync="editorValue" height="calc(100vh - 316px)"
          ></wangEditor>
        </div>
        <div class="btns" v-if="openType==3">
          <el-button @click="handleClose">关闭</el-button>
        </div>
        <div class="btns" v-else>
          <div style="display: flex;align-items: center;;flex: 1" v-if="topicType==3">
            <el-button
              type="primary"
              icon="el-icon-plus"
              style="width: 100px; height: 25px; padding: 0"
              plain
              @click="handleAddBlank"
            >插入填空符
            </el-button>
            <div style="margin-left: 15px">
              *填空符由英文括号以及三个下划线组成,例: ___
            </div>
          </div>
          <el-button @click="handleClose">取消</el-button>
          <el-button type="primary" @click="sureConfirm">确定</el-button>
        </div>
      </template>
      <template v-if="topicItem">
        <div class="editor_content">
          <div class="" v-html="$renderedDescription(topicItem.content)"></div>
          <!--    单选题部分        -->
          <el-radio-group
            v-removeAriaHidden
            disabled
            v-model="topicItem.answer"
            v-if="topicItem.topicType == 0"
          >
            <el-radio
              style="display: flex;flex-wrap: wrap;margin-top: 10px"
              v-for="(answerItem, answerIndex) in topicItem.ccTopicOptionList" :key="answerIndex" :label="answerItem.label"
            >
              <span v-html="$renderedDescription(`${answerItem.optionLabel}、${answerItem.optionValue}`)"></span>
            </el-radio>
          </el-radio-group>
          <!--    多选题部分        -->
          <el-checkbox-group
            disabled
            v-if="topicItem.topicType == 1"
          >
            <el-checkbox
              v-model="topicItem.answer"
              style="display: flex;flex-wrap: wrap;margin-top: 10px"
              v-for="(answerItem, answerIndex) in topicItem.ccTopicOptionList" :key="answerIndex" :label="answerItem.label"
            >
              <span v-html="$renderedDescription(`${answerItem.optionLabel}、${answerItem.optionValue}`)"></span>
            </el-checkbox>
          </el-checkbox-group>
        </div>
        <div class="btns">
          <el-button @click="handleClose">关闭</el-button>
        </div>
      </template>
    </div>
  </el-drawer>
</template>

<script>
import wangEditor from '@/components/Editor/wangEditor'

export default {
  name: 'editDrawer',
  components: {
    wangEditor
  },
  data() {
    return {
      editorValue: ''
    }
  },
  props: {
    show: {
      type: Boolean,
      default: false
    },
    requiredEditor: {
      type: Boolean,
      default: true
    },
    title: {
      type: String,
      default: '富文本导入'
    },
    propEditorValue: {
      type: [String],
      default: '<p><br></p>'
    },
    topicItem: {
      type: [Object],
      default: null
    },
    topicType: {
      type: [String, Number],
      default: ''
    },
    openType: {
      type: [String, Number],
      default: 1
    }
  },
  watch: {
    show(val) {
      if (val) {
        this.editorValue = this.propEditorValue
      }
    }
  },
  mounted() {
  },
  methods: {
    uploadWordToNode(e) {
      console.log('uploadWordToNode', e)

    },
    handleAddBlank() {
      this.editorValue += '<p>___</p>'
      console.log(this.editorValue)
    },
    sureConfirm() {
      if((this.editorValue == '<p><br></p>' || !this.editorValue) && this.requiredEditor){
        this.$modal.msgWarning('请输入内容')
        return
      }
      this.$emit('sureConfirm', this.editorValue)
      this.$emit('update:show', false)
    },
    handleClose() {
      this.$emit('update:show', false)
    }
  }
}
</script>

<style scoped lang="scss">
.editor_container {
  display: flex;
  flex-direction: column;
  padding: 0 40px;
  box-sizing: border-box;

  .editor_content {
    width: 100%;
    height: calc(100vh - 180px);
    overflow: auto;
  }

  .btns {
    width: 100%;
    display: flex;
    justify-content: flex-end;
    margin-top: 20px;
  }
}

//富文本回显样式
::v-deep h5,
.h5 {
  font-size: 14px;
}

::v-deep h4,
.h4 {
  font-size: 16px;
  font-weight: bold;
}

::v-deep h3,
.h3 {
  font-size: 18px;
  font-weight: bold;
}

::v-deep h2,
.h2 {
  font-size: 20px;
  font-weight: bold;
}

::v-deep h1,
.h1 {
  font-size: 22px;
  font-weight: bold;
}

::v-deep i {
  font-style: italic;
}

::v-deep .w-e-toolbar .w-e-menu i {
  font-style: normal;
}

::v-deep ol {
  list-style-type: decimal;
}

/* ul ol 样式 */
::v-deep ol {
  margin: 10px 0 10px 22px;
  list-style-type: decimal;
}

::v-deep ul {
  margin: 10px 0 10px 22px;
  list-style-type: disc;
}

/* table 样式 */
::v-deep table {
  border-top: 1px solid #ccc;
  border-left: 1px solid #ccc;
}

::v-deep table td,
::v-deep table th {
  border-bottom: 1px solid #ccc;
  border-right: 1px solid #ccc;
  padding: 3px 5px;
  height: 32px;
}

::v-deep table th {
  border-bottom: 2px solid #ccc;
  text-align: center;
  background-color: #f1f1f1;
}

/* blockquote 样式 */
::v-deep blockquote {
  display: block;
  border-left: 8px solid #d0e5f2;
  padding: 5px 10px;
  margin: 10px 0;
  line-height: 1.4;
  min-height: 24px;
  font-size: 100%;
  background-color: #f1f1f1;
}

/* code 样式 */
::v-deep code {
  display: inline-block;
  background-color: #f1f1f1;
  border-radius: 3px;
  padding: 3px 5px;
  margin: 0 3px;
}

::v-deep pre code {
  display: block;
}

::v-deep a {
  text-decoration: underline;
  color: #5592e5;
}

::v-deep .el-icon-close {
  font-style: normal !important;
}
</style>
